package xx.ring.db;

import java.sql.*;

public class DBHelper {
	
	public Connection getConn() throws SQLException{
		try {
			Class.forName("com.mysql.jdbc.Driver");
			return DriverManager.getConnection("jdbc:mysql://localhost:3306/ring?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true", "root", "SYC2020@");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw new RuntimeException();
		}catch (SQLException e) {
			e.printStackTrace();
			throw new SQLException();
		}
	}
	
	public void closeConn(Connection conn){
		try {
			if(conn!=null)
				conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void closeConn(Connection conn, PreparedStatement pstat){
		try {
			if(pstat!=null)
				pstat.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			closeConn(conn);
		}
	}
	
	public void closeConn(Connection conn, PreparedStatement pstat, ResultSet rs){
		try {
			if(rs!=null)
				rs.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			closeConn(conn, pstat);
		}
	}

}
